<?php


namespace App\Console\Commands\Statistics;


use Illuminate\Console\Command;

class SystemSerial extends Command
{
    //命令名
    protected $signature = 'system-serial';

    //命令描述
    protected $description = '统计系统流水';

    public function __construct()
    {
        parent::__construct();
    }

    //业务处理
    public function handle()
    {
        //更新一下昨天的数据
        $yesterday = date('Y-m-d', strtotime("-1 day"));
        $yesterdayLatestStatisticTime = app('model_system_everyday_serial')->getLatestUpdateTime($yesterday);
        if (empty($yesterdayLatestStatisticTime) || strtotime($yesterdayLatestStatisticTime) <= strtotime($yesterday . ' 23:59:59')) {
            app('repo_data_statistics')->systemTodaySerial($yesterday);
            app('repo_data_statistics')->roomTodaySerial($yesterday);
            app('repo_data_statistics')->mallTodaySerial($yesterday);
        }

        //系统今日流水统计
        app('repo_data_statistics')->systemTodaySerial();
        //房间今日流水统计
        app('repo_data_statistics')->roomTodaySerial();
        //房间总流水统计
        app('repo_data_statistics')->roomSerial();
        //商城每日流水
        app('repo_data_statistics')->mallTodaySerial();


        if (time() > strtotime('2021-09-29 15:45:00') && time() < strtotime('2021-09-29 15:55:00')) {

            $startDate = '2021-09-01';

            while (true) {

                //系统今日流水统计
                app('repo_data_statistics')->systemTodaySerial($startDate);
                //房间今日流水统计
                app('repo_data_statistics')->roomTodaySerial($startDate);
                //商城今日流水
                app('repo_data_statistics')->mallTodaySerial($startDate);

                $startDate = date('Y-m-d', strtotime("$startDate +1 day"));
                if ($startDate > date('Y-m-d')) break;
            }
            //房间总流水统计
            app('repo_data_statistics')->roomSerial();
        }
    }
}